#ifndef ITEM_STACK_H
#define ITEM_STACK_H

#include "boost/shared_ptr.hpp"

#include "Item.h"
#include "AnimatedSprite.h"

class ItemStack
{
public:
	ItemStack();
	ItemStack(const ItemPtr& item, size_t stack, size_t maxStack);
	virtual ~ItemStack();

    ItemStack& operator=(const ItemStack& rhs);

	friend bool operator==(const ItemStack& lhs, const ItemStack& rhs);
    friend bool operator<(const ItemStack& lhs, const ItemStack& rhs);

    ItemPtr getItem() const;

    size_t getStack() const;
    void setStack(size_t stack);

    size_t getMaxStack();

    AnimatedSpritePtr getIcon() const;

    int addItems(size_t numberToAdd); // returns remaining items
protected:
    ItemPtr item;
    size_t stack;
    size_t maxStack;
    AnimatedSpritePtr icon;
};

typedef boost::shared_ptr<ItemStack> ItemStackPtr;

class IdEqual
{
public:
    IdEqual(const ItemStack& stack)
    : stack(stack)
    {
    }

    bool operator()(const ItemStack& rhs) const
    {
        return stack.getItem()->getId() == rhs.getItem()->getId();
    }
private:
    const ItemStack& stack;
};

class IdsEqual
{
public:
    bool operator()(const ItemStack& lhs, const ItemStack& rhs) const
    {
        return lhs.getItem()->getId() == rhs.getItem()->getId();
    }
};

class IdLessThan
{
public:
    bool operator()(int itemId, const ItemStack& stack)
    {
        return itemId < stack.getItem()->getId();
    }
};

class IdGreaterThan
{
public:
    bool operator()(int itemId, const ItemStack& stack)
    {
        return itemId > stack.getItem()->getId();
    }
};

#endif